﻿using CXW.Core.Sharp.Services;
using DevExpress.XtraBars;
using System.Drawing;

namespace CXW.Core.Sharp.Gui
{
    /// <summary>Represents a sub-menu</summary>
    public class BarSubItemExt : BarSubItem, IStatusUpdate
    {
        Codon codon = null;
        /// <summary>显示内容根据此属性获取资源文件</summary>
        public string Language { get; private set; }

        /// <summary>构造函数</summary>
        /// <param name="codon"></param>
        public BarSubItemExt(Codon codon)
        {
            this.codon = codon;
            Name = codon.Id;
            Language = codon.Properties["language"];
            Glyph = (Image)ResourceService.GetObject(codon.Properties["icon"]);

            UpdateText();
        }

        string ResourceServiceLanguage = "";
        /// <summary>更新UI显示文字</summary>
        public void UpdateText()
        {
            if (ResourceServiceLanguage != ResourceService.Language)
            {
                LoggingService.DebugFormatted("1 Name = {0},Caption = {1}", Name, Caption);
                ResourceServiceLanguage = ResourceService.Language;
                Caption = LanguageHelper.GetText(codon);
                LoggingService.DebugFormatted("--2 Name = {0},Caption = {1}", Name, Caption);
            }
        }

        /// <remark/>
        public override string ToString()
        {
            return string.Format("BarSubItemExt Name = {0},Caption = {1}", Name, Caption);
        }
    }
}
